using System;
using System.Collections.Generic;
using System.Text;
using Mpi.Common.Collections;
using System.ComponentModel;

namespace Xeml.Document
{
    public class Observation : XemlAnnotatableObject
    {
        private Individual _individual;
        private TimeSpan _duration;
        private bool _destructive;
        private bool _individualInfluence;
        private PartitionCollection _partitions;
        private DevelopmentalStageCollection _stages;
        private IndividualsPool _individualsPool;
        private int _id;

        #region Properties

        public int Id
        {
            get { return this._id; }
            set { this._id = value; }
        }

        public bool IndividualInfluence
        {
            get
            {
                return _destructive ? true : _individualInfluence;
            }
            set
            {

                _individualInfluence = value;
            }
        }

        public bool Destructive
        {
            get { return _destructive; }
            set { _destructive = value; }
        }

        public TimeSpan Duration
        {
            get { return _duration; }
            set { _duration = value; }
        }

        public Individual Individual
        {
            get { return _individual; }
            set
            {
                if (_individualsPool == null)
                    throw new ArgumentException("No pool is setted up.");
                if (_individualsPool.Individuals.Contains(value))
                {
                    _individual = value;
                }
                else
                    throw new ArgumentException("The individual is not a member of the pool");
            }
        }

        public PartitionCollection Partitions
        {
            get
            {
                return _partitions;
            }

        }

        public DevelopmentalStageCollection DevelopmentalStages
        {
            get
            {
                return _stages;
            }
        }

        public IndividualsPool IndividualsPool
        {
            get
            {
                return _individualsPool;
            }
            set
            {
                this._individualsPool = value;
            }
        } 
        #endregion

        #region ctors
        public Observation()
        {
            _stages = new DevelopmentalStageCollection(this);
            _partitions = new PartitionCollection(this);
            _id = XemlCore.Indexing.ObservationIndexer.Instance.NextId();
        }

        public Observation(Observation o)
            : this()
        {
            this._id = o.Id;
            this._individualInfluence = o.IndividualInfluence;
            this._destructive = o.Destructive;
            this._duration = o.Duration;
            this._individual = o.Individual;
            this._individualsPool = o._individualsPool;
            foreach (Partition part in o.Partitions)
            {
                this._partitions.Add(new Partition(part));
            }
            foreach (Term t in o.DevelopmentalStages)
            {
                _stages.Add(new Term(t));
            }
        }

        #endregion

     
        private ObservationCollection _collection;
        public ObservationCollection Collection
        {
            get
            {
                return this._collection;
            }
            set
            {
                if (value != _collection)
                {
                    this._collection = value;
                }
            }
        }

      

    

  
    }
}
